package test.com.googlecode.likesql.converter;

import java.util.List;

import junit.framework.TestCase;

import com.googlecode.likesql.constant.SqlConstant;
import com.googlecode.likesql.converter.Converter;
import com.googlecode.likesql.converter.ConverterTable;
import com.googlecode.likesql.converter.DefaultConverter;

/**
 * @author Johny Huang
 *
 */
public class ConverterTableTester extends TestCase {

	public static class Example{
		public String name;
	}
	
	public static class ExampleConverter implements Converter{

		public String toSql(Object obj) {
			Example exp=(Example)obj;
			return exp.name;
		}

		public String toTemplate(Object obj) {
			return String.valueOf(SqlConstant.CHAR_FOR_REPLACE);
		}

		public List toValueList(Object obj) {
			return null;
		}
		
	}
	
	public void test_register(){
		ConverterTable table=ConverterTable.getInstance();
		table.register(Example.class, new ExampleConverter());
		
		assertTrue(table.getConverter(Example.class.getName()) instanceof ExampleConverter);
	}
	
	public void test_unregister(){
		ConverterTable table=ConverterTable.getInstance();
		table.register(Example.class, new ExampleConverter());
		
		assertTrue(table.getConverter(Example.class.getName()) instanceof ExampleConverter);
		
		table.unregister(Example.class);
		
		assertTrue(table.getConverter(Example.class.getName()) instanceof DefaultConverter);
	}
}
